package com.yoga.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yoga.dao.AdminMapper;
import com.yoga.model.Admin;
import com.yoga.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yan
 * @date 2025/8/18
 */
@CacheConfig(cacheNames = "com.yoga.service.impl.AdminServiceImpl")
@Service
public class AdminServiceImpl implements AdminService {
    private AdminMapper adminMapper;
    @Autowired
    public void setAdminMapper(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }

    @Override
    public Page<Admin> findAll(Page<Admin> page, Admin admin) {
        return adminMapper.findAll(page,admin);
    }



    @CacheEvict(allEntries = true)
    @Override
    public boolean add(Admin admin) {
        return adminMapper.insert(admin)>0;
    }

    @CacheEvict(allEntries = true)
    @Override
    public boolean update(Admin admin) {
        return adminMapper.updateById(admin)>0;
    }

    @CacheEvict(allEntries = true)
    @Override
    public boolean deleteById(Integer id) {
        return adminMapper.deleteById( id)>0;
    }

    @Cacheable(key = "'username:' + #username")
    @Override
    public Admin findByUsername(String username) {
        return adminMapper.findByUsername(username);
    }


}
